// Proxy 对象

const person = {
    name: 'zce',
    age: '20',
};

const personProxy = new Proxy(person, {
    get(target, property) {
        return property in target ? target[property] : 'default';
        // return '100'
    },
    set(target, property, value) {
        if (property === 'age') {
            if (!Number.isInteger(value)) {
                throw new TypeError(`${value} is not an int`);
            }
        }
        target[property] = value;
    },
});

personProxy.age = '10';
personProxy.gender = true;

console.log(personProxy.name);
console.log(personProxy.xxx);

// Proxy 对比 Object.defineProperty()

// 1. 能做的更多
// get set has deleteProperty getPrototypeOf setPrototypeOf
// isExtensible prevebtExtensible getOwnPropertyDescriptor
// defineProperty ownKeys apply constrcutor

// 2. 对数组的监视

// 3. 不会对原有对象代码侵入
